<!--#include file="../../core/common/Conn.asp" -->
<!--#include file="../../core/common/Limit.asp" -->
<%
	dim action
	action = request.QueryString("action")
	if action = "edit" then
		call edit
	else
		call default
	end if
	
	dim MODULE_SELECT,PID_SELECT
	dim NAME,MODULEID,PID,ID
	dim selected,SpaceStr
	
	'加载默认数据
	sub default
		ID = request.QueryString("ID")
	
		'获取默认数据
		dim rs,sql
		sql = "select * from [SUBJECT] where ID = '"& ID &"'"
		set rs = db.query(sql)
		if not rs.eof then
			NAME = rs("NAME")
			MODULEID = rs("MODULEID")
			PID = rs("PID")
		end if
		rs.close
		set rs = nothing
	
		'初始化两个Select标签
		MODULE_SELECT = ""
		PID_SELECT = ""
		
		'生成栏目类型的Select标签
		sql = "select * from [MODULE] order by PX asc"
		set rs = db.query(sql)
		do while not rs.eof
			if rs("ID") = MODULEID then
				selected = "selected=""selected"""
			else
				selected = ""
			end if
			MODULE_SELECT = MODULE_SELECT & "<option value="""& rs("ID") &""" "& selected &">"& rs("NAME") &"</option>"
			rs.movenext
		loop
		rs.close
		set rs = nothing
		
		'生成上级栏目的Select标签
		sql = "select * from [SUBJECT] order by ID asc"
		set rs = db.query(sql)
		do while not rs.eof
			SpaceStr = space(((len(rs("ID")) / 3) - 1) * 3)
			SpaceStr = replace(SpaceStr," ","&nbsp;")
			if PID = rs("ID") then
				selected = "selected=""selected"""
			else
				selected = ""
			end if
			PID_SELECT = PID_SELECT & "<option value="""& rs("ID") &""" "& selected &">"& SpaceStr & rs("NAME") &"</option>"
			rs.movenext
		loop
		rs.close
		set rs = nothing
	end sub
	
	'修改栏目
	sub edit
		ID = request.Form("ID")
		NAME = request.Form("NAME")
		MODULEID = request.Form("MODULEID")
		PID = request.Form("PID")

		dim rs,sql
		sql = "select * from [SUBJECT] where ID = '"& ID &"'"
		set rs = db.query(sql)
		if not rs.eof then
			rs("NAME") = NAME
			rs("MODULEID") = MODULEID
			rs("PID") = PID
			rs.update
		end if
		rs.close
		set rs = nothing
		
		response.Redirect("list.asp")
	end sub
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CMSLite for ASP</title>
<link href="../resource/css/reset.css" rel="stylesheet" type="text/css" />
<link href="../resource/css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../resource/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../resource/js/common.js"></script>
</head>

<body id="body">
	<div class="title_bar">
	修改栏目
	</div>
	<form action="?action=edit" method="post">
	<p>
		<label>栏目名</label>
		<input type="text" class="textbox" name="NAME" value="<%=NAME%>" />
	</p>
	<p>
		<label>栏目类型</label>
		<select name="MODULEID" id="MODULEID" class="style_1">
			<option value="0">无</option>
			<%=MODULE_SELECT%>
		</select>
	</p>
	<p>
		<label>上级栏目</label>
		<select disabled="disabled" class="style_1">
			<option value="0">无</option>
			<%=PID_SELECT%>
		</select>
		<input type="hidden" name="PID" id="PID" />
	</p>
	<p>
		<input type="submit" class="button_1" value="修改" />
		<input type="button" class="button_1" value="取消" onclick="location.href='list.asp';" />
		<input type="hidden" name="ID" value="<%=ID%>" />
	</p>
	</form>
</body>
</html>
